home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / dnet / dshterm1_0.lha / lib / st / examples / asynctest.c next >
Encoding:
C/C++ Source or Header  |  1992-02-04  |  1.8 KB  |  83 lines

  1. /* Asyncronous IO routines */
  2.  
  3.  
  4. #include <exec/types.h>
  5. #include <exec/memory.h>
  6. #include <exec/ports.h>
  7. #include <dos/dos.h>
  8. #include <dos/dosextens.h>
  9. #include <proto/exec.h>
  10. #include <proto/dos.h>
  11. #include <st/st_proto.h>
  12.  
  13. long    out = NULL, in = NULL, err = NULL;
  14. char    prg[40];
  15.  
  16. main(int argc, char *argv[])
  17. {
  18. struct AFileHandle *afh = NULL, *afh2 = NULL;
  19. char    buf[2][100], buf2[1000];
  20. long    n, w, n2;
  21.  
  22.     out = Output();
  23.     in    = Input();
  24.     err = Open("*",MODE_OLDFILE);
  25.     fpf(err, "%08lx %08lx %08lx\n", out, err, in);
  26.  
  27.     spf(prg, sizeof(prg), "%s[%s]", argv[0], FindTask(NULL)->tc_Node.ln_Name);
  28.  
  29. /* OPEN THE FILE */
  30.  
  31. /*    if(!(afh = AEasyOpen(NULL, argv[1], MODE_OLDFILE))) {
  32.         fpf(err,"Couldn't open '%s' for input\n", argv[1]);
  33.         goto endit;
  34.     } */
  35.  
  36.     if(!(afh2 = AEasyMakeFD2AFD(NULL, in))) {
  37.         fpf(err,"Couldn't open input\n");
  38.         goto endit;
  39.     } 
  40.  
  41.  
  42.     if(!(afh = AEasyOpen(afh, argv[1], MODE_OLDFILE))) {
  43.         fpf(err,"Couldn't open '%s' for input\n", argv[1]);
  44.         goto endit;
  45.     }
  46.  
  47.     fpf(err,"%s: Opened the files ok!\n", prg);
  48.  
  49.     fpf(err,"Trying to change %s into raw mode\n", argv[1]);
  50.     ASendPacket(afh, ACTION_SCREEN_MODE, 1, 0, 0, 0);
  51.     n = AResultWait(afh2);
  52.     fpf(err,"mode change result = %ld\n",n);
  53.  
  54.  
  55. /** START A READ FROM THE SECOND FILE  */
  56.     ARead(afh2, buf2, 1000);
  57.  
  58. /** READ THE ENTIRE FIRST FILE & PRINT */
  59.     fpf(out,"Double buffered reading of '%s'\n", argv[1]);
  60.     w = 0;
  61.     ARead(afh, buf[w], 100);
  62.     for(n = 1; n ; ) {
  63.         while((AStatus(afh)) == ASTATUS_BUSY) Write(out,"x",1);
  64.         n = ARead(afh, buf[1-w], 100);
  65.         fpf(out,"%ld ",n);
  66.         if( n > 0 )
  67.         { Write(out, buf[w], n); fpf(out, "lastchar: %ld\n", buf[w][n-1]); }
  68.         w = 1 - w;
  69.     }
  70.  
  71. /** SEE WHAT WAS READ FROM THE OTHER FILE */
  72.     fpf(out,"\nThe following was read from '%s' also:\n", argv[2]);
  73.     Write(out, buf2, AResultWait(afh2));
  74.  
  75. endit:
  76.     SafeClose(&err);
  77.     ASafeEasyClose(&afh);
  78.     ASafeEasyClose(&afh2);
  79.  
  80.     return(0);
  81. }
  82.  
  83.